package org.aeon.gamechatnest.util;

import java.util.Objects;

/**
 * @author: MissingAeon
 * @date: 2024/5/9 15:04
 * @description:
 */
public class StringUtils {

    public static boolean contains(String str, String substring) {
        if (str == null || substring == null) {
            return false;
        }
        return str.contains(substring);
    }

    public static boolean equals(String str, String str2) {
        if (str != null)
            return str.equals(str2);
        return str2 == null;
    }

    public static boolean isEmpty(String str) {
        return Objects.isNull(str) || str.isEmpty();
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }


    public static String selectNonEmpty(String first, String alternative) {
        if (isEmpty(alternative)) {
            // 空指针
            throw new NullPointerException("alternative");
        }
        return isEmpty(first) ? alternative : first;
    }
}
